package com.sh.rbac.domain.enums;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;

import java.util.stream.Stream;

/**
 * 操作类型枚举
 *
 * @author wb
 * @since 2024-07-07
 */

@Schema(description = "操作类型枚举")
@Getter
public enum OperationTypeEnum {

    ADD(0, "新增"),
    UPDATE(1, "修改"),
    DELETE(2, "删除"),
    BATCH_DELETE(3, "批量删除"),
    OTHER(4, "其他"),
    EXPORT(5, "导出"),
    IMPORT(6, "导入");

    @Schema(description = "操作类型编码")
    private final Integer code;

    @Schema(description = "操作类型描述")
    private final String desc;

    OperationTypeEnum(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    // 根据 code 获取 desc
    public static String getDescByCode(Integer code) {
        return Stream.of(values())
                .filter(bean -> bean.code.equals(code))
                .findAny()
                .orElse(OTHER)
                .getDesc();
    }
}
